package com.coder4j.platform;

import com.coder4j.starter.tools.util.AESUtils;
import com.coder4j.starter.tools.util.Base64Utils;
import com.coder4j.starter.tools.util.Md5Utils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class PasswordUtils {
    private final static String AES_KEY = "keller2024-5-8";

    /**
     * 密码加密
     * @param password
     * @return
     */
    public static String encrypt(@NonNull String password) {
       return  Md5Utils.getMd5String(AESUtils.encodeAES(Base64Utils.encodeBase64(password),AES_KEY));
    }

    /**
     * 校验密码是否一致
     * @param originalString 原始密码
     * @param encryptedString 加密后的密码
     * @return
     */
    public static boolean checkPassword(@NonNull String originalString,@NonNull String encryptedString) {
        return encrypt(originalString).equals(encryptedString);
    }

    public static void main(String[] args) {
        String password = "123456";

        String encrypt = encrypt(password);
        log.info("加密后：{}",encrypt);
        log.info("{}",checkPassword(password,encrypt));
    }
}
